package com.web.hawaste.controller;

import com.web.hawaste.utils.ResultBean;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * YangSuzy 软件工作室
 * 类名: MyException
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/10/14 17:37
 */
@RestControllerAdvice
public class MyException {
    @ExceptionHandler(AuthorizationException.class)
    public ResultBean handlerException1(AuthorizationException e) {
        ResultBean error = ResultBean.error();
        error.setMsg("该用户无权访问该功能");
        return error;
    }

    @ExceptionHandler({IncorrectCredentialsException.class, UnknownAccountException.class})
    public ResultBean handlerException2(Exception e){
        ResultBean error = ResultBean.error();
        error.setMsg("账号或密码错误");
        return error;
    }
}
